﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace PolePosition.v3.Desktop.Selectors.Controls
{
    public partial class AssetTypes : DialogEditBase
    {
        public EventHandler<ItemCheckedEventArgs> AssetChecked;

        public AssetTypes()
        {
            InitializeComponent();

            listSelectorAssetType.ItemChecked += ItemChecked;
        }
 
        private void ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            AssetChecked(this, e);
        }

        private void AssetTypes_Load(object sender, EventArgs e)
        {
            BindLists();
        }

        [DefaultValue(false)]
        public bool ListEnabled
        {
            get
            {
                return listSelectorAssetType.Enabled;
            }
            set
            {
                listSelectorAssetType.Enabled = value;
            }
        }

        private bool m_AllowMultiSelect = true;
        [DefaultValue(true)]
        public bool AllowMultiSelect
        {
            get
            {
                return m_AllowMultiSelect;
            }
            set
            {
                m_AllowMultiSelect = value;

                listSelectorAssetType.AllowMultiSelect = value;

                if (value)
                {
                    panelSelectors.Dock = DockStyle.None;
                    panelSelectors.Location = new Point(10, 49);
                    panelSelectors.Padding = new Padding(0, 0, 0, 0);
                    listSelectorAssetType.Dock = DockStyle.None;
                    listSelectorAssetType.Location = new Point(0, 0);
                }
                else
                {
                    panelSelectors.Dock = DockStyle.Fill;
                    panelSelectors.Padding = new Padding(10, 0, 10, 0);
                    listSelectorAssetType.Dock = DockStyle.Fill;
                }
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string SelectedAssetTypeList
        {
            get { return listSelectorAssetType.GetSelectedValueList<string>(); }
            set 
            { 
                listSelectorAssetType.SetSelectedValueList<string>(value);
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public List<Common.Enumerations.AssetTypes> SelectedAssets
        {
            get
            {
                return listSelectorAssetType.GetSelectedItems<Common.Enumerations.AssetTypes>();
            }
            set
            {
                listSelectorAssetType.SetSelectedItems<Common.Enumerations.AssetTypes>(value);
            }
        }

        private void BindLists()
        {
            listSelectorAssetType.ListItems.Clear();

            ListViewItem _Item = listSelectorAssetType.ListItems.Add(Common.Enumerations.AssetTypes.Transmission.ToString());
            _Item.Tag = Common.Enumerations.AssetTypes.Transmission;

            _Item = listSelectorAssetType.ListItems.Add(Common.Enumerations.AssetTypes.Distribution.ToString());
            _Item.Tag = Common.Enumerations.AssetTypes.Distribution;

            _Item = listSelectorAssetType.ListItems.Add(Common.Enumerations.AssetTypes.Meters.ToString());
            _Item.Tag = Common.Enumerations.AssetTypes.Meters;

            _Item = listSelectorAssetType.ListItems.Add(Common.Enumerations.AssetTypes.Transformers.ToString());
            _Item.Tag = Common.Enumerations.AssetTypes.Transformers;

            _Item = listSelectorAssetType.ListItems.Add(Common.Enumerations.AssetTypes.Reclosers.ToString());
            _Item.Tag = Common.Enumerations.AssetTypes.Reclosers;

            _Item = listSelectorAssetType.ListItems.Add(Common.Enumerations.AssetTypes.Sectionalizers.ToString());
            _Item.Tag = Common.Enumerations.AssetTypes.Sectionalizers;
            
            listSelectorAssetType.SelectNone();
            listSelectorAssetType.ResizeColumnForListItems();
        }
    }
}
